#!/bin/bash
cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf
LOGS_DIR=$DEPLOY_DIR/logs
BIN_DIR=$DEPLOY_DIR/bin
RESTART_LOG_FILE=$LOGS_DIR/am-subaio-api.log

if [ ! -d LOGS_DIR ];then
	mkdir LOGS_DIR
fi

if [ ! -f $RESTART_LOG_FILE ];then
	touch $RESTART_LOG_FILE
fi

sleep 2
while [ 1 ]
do
	SERVER_PID=`ps -ef | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
	if [ ! -n "$SERVER_PID" ]; then
		bash $BIN_DIR/payserver.sh start
		NEW_SERVER_PID=`ps -ef | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
		echo `date +%Y-%m-%d` `date +%H:%M:%S` 'pay server restart SERVER_PID ' $NEW_SERVER_PID >> $RESTART_LOG_FILE
	fi
	sleep 2
done
